package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ReportService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@Api(tags = "数据统计相关接口")
@Slf4j
@RequestMapping("/admin/report")
@RestController
public class ReportController {

    @Autowired
    private ReportService reportService;

    @ApiOperation("营业额统计")
    @GetMapping("/turnoverStatistics")
     public Result<TurnoverReportVO> turnoverReport(
             @DateTimeFormat(pattern = "yyyy-MM-dd")//使日期传过来的格式固定
             LocalDate begin,
             @DateTimeFormat(pattern = "yyyy-MM-dd")
             LocalDate end
    ) {
        log.info("报表数据统计：营业额统计");
        return Result.success(reportService.turnoverReport(begin,end));
     }

     @GetMapping("/userStatistics")
     public Result<UserReportVO> userReport(
             @DateTimeFormat(pattern = "yyyy-MM-dd")//使日期传过来的格式固定
             LocalDate begin,
             @DateTimeFormat(pattern = "yyyy-MM-dd")
             LocalDate end
     ){
        log.info("报表数据统计：用户统计");
        return Result.success(reportService.userReport(begin,end));
     }

     @GetMapping("/ordersStatistics")
     public Result<OrderReportVO> orderReport(
             @DateTimeFormat(pattern = "yyyy-MM-dd")//使日期传过来的格式固定
             LocalDate begin,
             @DateTimeFormat(pattern = "yyyy-MM-dd")
             LocalDate end
     ){
        log.info("报表数据统计：订单统计");
        OrderReportVO orderReportVO = reportService.getOrderReport(begin,end);
        return Result.success(orderReportVO);
     }


     @GetMapping("/top10")
     @ApiOperation("查询销量排名top10")
     public Result<SalesTop10ReportVO> salesTop10Report(
             @DateTimeFormat(pattern = "yyyy-MM-dd")//使日期传过来的格式固定
             LocalDate begin,
             @DateTimeFormat(pattern = "yyyy-MM-dd")
             LocalDate end
     ){
        log.info("报表数据统计：销量排名统计");
        SalesTop10ReportVO salesTop10ReportVO = reportService.getSalesTop10Report(begin,end);
        return Result.success(salesTop10ReportVO);
        }
}
